<?php
/**
 * Created by PhpStorm.
 * User: lenovo
 * Date: 2019/1/11
 * Time: 21:01
 */
class MysqlAsy{

    private  $db = null;

    public function __construct()
    {
        $this->db = new \Swoole\MySQL();

    }

    public function exec()
    {
        try{

            $this->db->connect(Conf::getConf() , function (swoole_mySQL $db, $result) {
                if(false === $result){
                    var_dump($db->connect_errno, $db->connect_error);
                    die;
                }
                $sql="select * from test";
                $db->query($sql,function (swoole_mysql $db,$result){

                    if(false === $result){

                    }elseif(true === $result){ //cur 返回bool

                    }else{
                        var_dump($result);
                    }
                    $db->close();
                });

            });
            return true;
        }catch (swoole_mysql_exception $e){
            return false;
            var_dump($e->getMessage());
        }
    }
}
class Conf{
    private static $conf=[];
    public static function getConf()
    {
        return self::$conf=[
            'host' => '127.0.0.1',
            'port' => 3306,
            'user' => 'root',
            'password' => 'V123!@#',
            'database' => 'swoole',
            'charset' => 'utf8', //指定字符集
            'timeout' => 2,  // 可选：连接超时时间（非查询超时时间），默认为SW_MYSQL_CONNECT_TIMEOUT（1.0）
        ];
    }

}
$db=new MysqlAsy();
$re=$db->exec();
var_dump($re);
echo 'mysql START '.PHP_EOL;

